#pragma once

#include <Ogre.h>
#include <OIS.h>
#include <opencv/highgui.h>
#include "kinetic.h"

class Base;

// bigger then quicker fade of F in keyboard mode playing
const float KBMODE_DEPRESS_RATE = 10.f;

// bigger then more active in keyboard mode playing
const float KBMODE_INCREASE_RATE = 5.f;

const float MAX_FRAME_TIME = 0.1f;
const float MIN_FRAME_TIME = 0.002f;

// Game time for start flying
const float SETOFF_TIME = 2.f; //sec

/* draft:
N[10/40]==0.25
NSolve[a == a*Exp[-0.25] + 0.25, a]
{{a -> 1.1302}}
*/

class Controler
{
private:
	// input devices
	Base* parent;
	OIS::InputManager* input_manager;
	OIS::Mouse* mouse;
	OIS::Keyboard* keyboard;
	CvCapture* capture;

	// camera result, height: -1..1  length: 0..1
	float left_height, left_length, right_height, right_length;

	// 
	float t_normal, t_pro;

	// flight drivers
	Kinetic* kinetic;

public:
	void init(Base* parent);
	OIS::InputManager* get_input_manager();
	OIS::Mouse* get_mouse();
	OIS::Keyboard* get_keyboard();
	void do_capture();
	std::vector<Ogre::String> get_camera_info();
	void capture_camera(int cam_id);
	CvCapture* get_capture();
	
	Kinetic* get_kinetic();
	// main driver function in game mode. apply kinetic module and link with controler to update the scene node
	void drive(bool is_pro, bool is_cam, Ogre::SceneNode* sn, OIS::Keyboard* kb, Ogre::Real time, HANDLE lock);

	void set_value(Ogre::Real left_len, Ogre::Real right_len, Ogre::Real left_hei, Ogre::Real right_hei);

	// called before setoff
	void setoff_init(HANDLE lock);
	// drive to start. return 1 when started using UP, return 2 when started using RIGHT
	int setoff(bool is_cam, OIS::Keyboard* kb, Ogre::Real time, HANDLE lock);

	Controler();
	~Controler();
};